Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use one NavHost (with a single navigation scaffold) #102

Conversation

jdkoren
Copy link

@jdkoren jdkoren commented Sep 25, 2024

Consolidates all the navigation into one NavHost. A single NavigationSuiteScaffold is used to show top-level routes, with logic to hide some or all forms of navigation based on the current destination.

Fixes #96.

jdkoren added 19 commits August 29, 2024 10:04
Previously, the app had a NavHost but didn't actually call navigate.
NavHost's startDestination was read from external state (the currently
selected nav item), which led to some undesirable behaviors.
- NavHost itself was recomposed when selecting a nav item.
- Pressing back always exited the app because you were always at the
  start destination.

Now the NavHost has a stable startDestination, and nav item state is
driven by the NavHostController's current destination. Selecting a nav
item calls navigate, and the user always goes back through the
startDestination before exiting the app.
ksp = "2.0.0-1.0.21"
lifecycle = "2.8.4"
material3 = "1.2.1"
media3 = "1.4.1"
navigation = "2.7.7"
navigation = "2.8.0-rc01"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since 2.8.1 is released, can we use that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

gradle/libs.versions.toml Outdated Show resolved Hide resolved
Base automatically changed from jdk/codelab_2024_fixup to codelab_improve_android_experience_2024 October 2, 2024 17:07
…ce_2024' into jdk/one_nav_host__single_nav_scaffold
@jdkoren jdkoren merged commit 328dcc6 into codelab_improve_android_experience_2024 Oct 14, 2024
2 checks passed
@jdkoren jdkoren deleted the jdk/one_nav_host__single_nav_scaffold branch October 14, 2024 15:53
ashnohe pushed a commit that referenced this pull request Dec 9, 2024
* Deduplicate lifecycle runtime compose

* kotlin 2.0 and compose gradle plugin

* update test & other versions

* Call navigate instead of recomposing HavHost

Previously, the app had a NavHost but didn't actually call navigate.
NavHost's startDestination was read from external state (the currently
selected nav item), which led to some undesirable behaviors.
- NavHost itself was recomposed when selecting a nav item.
- Pressing back always exited the app because you were always at the
  start destination.

Now the NavHost has a stable startDestination, and nav item state is
driven by the NavHostController's current destination. Selecting a nav
item calls navigate, and the user always goes back through the
startDestination before exiting the app.

* Use type-safe navigation

* Make a package for navigation routes

* Migrate to type safe routes for main navhost

* Push Scaffold down to each top-level destination

* Extract nav suite scaffold to another composable

* Move ChatList, move and rename HomeViewModel

* Move Settings to its own package

* Remove Home and put its destinations in Main NavHost

* Remove Home composable and rename file

* Add NavigationSuiteScaffold around NavHost

* Change navigation layout type based on current destination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants